

<script>

export default {
  render: function (h) {

    let ex_super_desc = null

    if (this.descOption) {
      const desc_scopedSlots = {}
      this.descOption.model.filter(it => it.slot && this.$scopedSlots[it.slot]).forEach(it => {
        desc_scopedSlots[it.slot] = (props) => {
          return this.$scopedSlots[it.slot](props)
        }
      })
      ex_super_desc = h('ex_super_desc', {
        class: this.descOption.class,
        props: {
          data: this.descData, ..._.merge({ attrs: _.cloneDeep(this.descAttrs) }, this.descOption)
        }, scopedSlots: desc_scopedSlots
      },
      )
    }

    return h('div', {
      class: 'flex_col flex_cell',
      directives: [{ name: 'loading', value: this.loading }]
    }, [
      ex_super_desc,
      this.tableOptions ?
        this.tableOptions.filter(it => it).map((table, index) => {
          const scopedSlots = {}
          table.model.filter(it => it.slot && this.$scopedSlots[it.slot]).forEach(it => {
            scopedSlots[it.slot] = (props) => {
              return this.$scopedSlots[it.slot](props)
            }
          })

          return h('ex_super_table', {
            props: { ...table, data: this.tableDatas[index], }, key: index, scopedSlots
          },
          )
        })

        : null,

    ])
  },
  data() {
    return {
      descAttrs: {
        size: 'small',
        column: 4,

      },
      descData: {},
      tableDatas: [],
      loading: false,
      params: "",
    }
  },
  props: {
    descOption: Object,
    tableOptions: Array,
    url: String,
    urlDataHandle: Function,
  },

  computed: {

  },
  methods: {
    show({ params, data, }) {

      this.params = params
      if (!_.isEmpty(data)) {
        _.forOwn(data, (value, key, object) => {
          this.descData[key] = value
        })
      }
      if (this.url) {

        this.loadData(params)
      }

    },

    loadData(params) {
      if (!params) params = this.params
      this.loading = true
      this.$ajax({
        url: this.url,
        method: 'post',
        data: params,
        success: (responseData) => {
          this.params = JSON.stringify(params)
          let data = this.urlDataHandle ? this.urlDataHandle(responseData, this) : {}
          _.forOwn(data, (value, key, object) => {
            this[key] = value
          })
        },
        complete: () => {
          this.loading = false
        }
      })
    },


  }
}
</script>
